package com.atguigu.rabbitmq.two;

import com.atguigu.rabbitmq.utils.RabbitMqUtils;
import com.rabbitmq.client.CancelCallback;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.DefaultConsumer;
import com.rabbitmq.client.DeliverCallback;

/**
 * 这是一个工作线程（相当于之前的消费者）
 * @author 连志阳
 * @since 2022/2/8
 */
public class Worker01 {
    //队列名称
    public static final String QUEUE_NAME = "hello";
    
    //接收消息
    public static void main(String[] args) throws Exception {
        Channel channel = RabbitMqUtils.getChannel();
    
        DeliverCallback deliverCallback = (consumerTag, message) -> {
            System.out.println("接收到的消息：" + new String(message.getBody()));
        };
        CancelCallback cancelCallback = consumerTag -> {
            System.out.println(consumerTag + "消息者取消消费接口回调逻辑");
        };
        /*
        消费者消费消息
        1.消费哪个队列
        2.消费成功之后是否要自动应答，true自动应答，false手动应答
        3.消费者未成功消费的回调
        4.消费者取消消费的回调
         */
        System.out.println("C2等待接收消息");
        channel.basicConsume(QUEUE_NAME, true, deliverCallback, cancelCallback);
        
    }
}
